package pl.edu.amu.wmi.kino.visualjavafx.model.animation.transformations;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import pl.edu.amu.wmi.kino.visualjavafx.model.animation.interpolators.Interpolation;
import pl.edu.amu.wmi.kino.visualjavafx.model.objects.VisualObject;

// <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
// #[regen=yes,id=DCE.E97DFF3F-E0C1-FBDE-5EF0-87BC16BE8F4D]
// </editor-fold> 
public class ChangeBorderWidth implements Transformation ,java.io.Serializable{

    // Code block for changeListeners support start
    protected PropertyChangeSupport propertySupport= new PropertyChangeSupport(this);
    public void addPropertyChangeListener(PropertyChangeListener listener) {
        propertySupport.addPropertyChangeListener(listener);
    }
    public void removePropertyChangeListener(PropertyChangeListener listener) {
        propertySupport.removePropertyChangeListener(listener);
    }
    // Code block for changeListeners support end

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.ED1DCCF4-B078-BEE9-F162-5594BA9EB428]
    // </editor-fold> 
    public ChangeBorderWidth () {
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.DDD886C5-3910-3427-E432-256F3CB70FDA]
    // </editor-fold> 
    @Override
    public Interpolation getInterpolation () {
        return this.myInterpolations[0];
    }

    @Override
    public Interpolation[] getInterpolations() {
        return this.myInterpolations;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.78AE6297-FF47-9286-3973-54EBF7A1546D]
    // </editor-fold> 
    @Override
    public void setInterpolation (Interpolation i) {
        Interpolation oldVal = this.myInterpolations[0];
        this.myInterpolations[0]=i;
        propertySupport.firePropertyChange( "Inerpolation" , oldVal, i);
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.0D81963D-61ED-D8AE-E451-28A6486A955F]
    // </editor-fold> 
    @Override
    public VisualObject transform (double howMuch, VisualObject transformable,VisualObject orginalTransformedObject) {

        if ((transformable instanceof WithBorder)==false){
            return transformable;
        }
        
        WithBorder res = (WithBorder)transformable;
        double width = res.getBorderWidth();
        width = this.getInterpolation().getValue(howMuch, width, this.destinedWidth);
        res.setBorderWidth(width);

        return (VisualObject)res;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.DD731515-B82D-458D-0B57-E189C5A4FE50]
    // </editor-fold> 
    public double getDestinedWidth () {
        return this.destinedWidth;
    }

    // <editor-fold defaultstate="collapsed" desc=" UML Marker "> 
    // #[regen=yes,id=DCE.FA659BFB-2C40-9F1E-8B69-BB53570B38AF]
    // </editor-fold> 
    public void setDestinedWidth (double val) {
        double oldVal = this.destinedWidth;
        this.destinedWidth=val;
        propertySupport.firePropertyChange( "destinedWidth" , oldVal, val);
    }

    private Interpolation[] myInterpolations=new Interpolation[1];
    private double destinedWidth=1.0d;



}

